%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% COMPUTE TOTAL DEMAND FOR DEFORESTATION AND PLOT THE CURVES

% "DEFORESTATION IN THE AMAZON:
% A UNIFIED FRAMEWORK FOR ESTIMATION AND POLICY ANALYSIS"

% by Eduardo Souza-Rodrigues

% This version: November 2018

% OBSERVATIONS: 
% Run this program after running "dem_def_reg.m" & "dem_def_compute_demand.m"

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% (A) COMPUTE TOTAL DEMAND

% I. Prepare the Data    

% Load Demand (calculated in "dem_def_compute_demand.m")
% Demand_farm_jc = [transfer' tot_demand_iv' tot_demand_ivqr'] 
load Demand_farm_1cp;
load Demand_farm_2cp;
load Demand_farm_3cp;
load Demand_farm_4cp;

% II. Define Variables

% Transfers/Taxes 
transfer_cp  = Demand_farm_1cp(:,1);

% Main Demand for Deforestation - IVQR
demand_def_cp1 = Demand_farm_1cp(:,3);
demand_def_cp2 = Demand_farm_2cp(:,3);
demand_def_cp3 = Demand_farm_3cp(:,3);
demand_def_cp4 = Demand_farm_4cp(:,3);
demand_def_cp  = demand_def_cp1 + demand_def_cp2 + demand_def_cp3 + demand_def_cp4;


%% (B) PLOT DEMAND CURVES

% All farms together & Total Demand
demand_def_fig = figure;
plot(demand_def_cp1/1000000,transfer_cp,'-.',demand_def_cp2/1000000,transfer_cp,'--',demand_def_cp3/1000000,transfer_cp,'b:',demand_def_cp4/1000000,transfer_cp,'r-',demand_def_cp/1000000,transfer_cp,'b--*')
xlabel('Agricultural Area (Million hectares)','fontsize',15)
ylabel('Taxes (US$/ha)','fontsize',15)
title('By Farm Size and Total','fontsize',16)
axis([-3 50 0 200])
h_legend=legend('Small','Small-Medium','Medium-Large','Large','Total Demand');
set(h_legend,'FontSize',17);
saveas(demand_def_fig,'DemDef.png')


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

